<template>
    <div id="tIndv">
        <div  v-bind:class="{sShow: showS==0}"><!--管理班级弹框-->
            <score v-bind:message3="showS" v-on:listenToChildEvent3="showMsgFromChild3" :workData="workData" v-on:setScore="setScore" ></score>
        </div>
        <table style="margin:0 0 0 0.6vw" width="96%" class="tTable" cellspacing="0" cellpadding="0">
            <thead >
                <tr>
                    <th  width="6%"><input type="checkbox" ref="ckb_head" name="check_box" @click="ckbAll"/></th>
                    <th  width="25%">学号</th>
                    <th width="18%">姓名</th>
                    <th width="24%">作业</th>
                    <th  width="10%">分数</th>
                    <th>操作</th>
                 </tr>
            </thead>
        </table>
        <div class="tableDiv" style="overflow-y:scroll;height:23vw;margin:0 0.8vw 0 0.6vw">
            <table class="tTable" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                    <tr  v-for="(stu,index) in stus_" onMouseOver="this.className='Off'" onmouseout="this.className='Up'">
                        <td  width="6%"><input type="checkbox"   @click="ckbsome(index)" ref="ckb"/></td>
                        <td @click="sendMsgToParent" width="25%" v-bind:style="{color:text_color[index]}">{{stu.num}}</td>
                        <td width="18%"  v-bind:style="{color:text_color[index]}">{{stu.name}}</td>
                        <td width="24%" v-bind:style="{color:text_color[index]}">{{stu.task}}</td>
                        <td width="10%">{{stu.score}}</td>
                        <td  style="font-weight:bold; " >
                            <span @click="down_studentWork(index)" style="font-weight:bold; text-decoration:underline;cursor: pointer;margin:0 0% 0 0;" >下载</span>
                            <span @click="showScore(index)" style="font-weight:bold; cursor: pointer;">评分</span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>
<script>
 import axios from 'axios'
     export default {
         data(){
             return{
                  workData:{},
                  props:["message"],
                  showS:0,
                  stus_:[],
                  text_color: [],
                  stus_data:[]
             }
         },
       props:[
         'stus'
       ],
//       mounted: function () {
//         console.log("1111");
//         console.log(this.currentView_);
//         console.log("1111");
//         var workMess=new Array();
//         for(var i= 1;i<this.currentView_.length;i++){
////             var puMess = {};
////           puMess.num = currentView_.name;
////           puMess.name = currentView_.studentID;
////           puMess.task =  currentView_.task;
////           puMess.task = currentView_.workName;
////           workMess.push(puMess);
//           this.stus = this.currentView_;
//         }
//
//
//       },
          watch:{
            'stus': function() {
                console.log('开始watch')
              this.stus_= this.stus;
              this.stus_data=this.stus;
             // console.log("我就看看",this.stus_,this.stus_);
             this.text_color=[]
              for(var i=0; i<this.stus.length;i++){
                 if(this.stus_[i].workStatus=="0"){
                    this.text_color.push('#e70012');//红色
                 }else if(this.stus_[i].workStatus=="-1"){
                     this.text_color.push('#dd8b02');//黄色
                 }else if(this.stus_[i].workStatus=="2"){
                    this.text_color.push('#018e3c');//绿色
                 }else{
                    this.text_color.push('#4d4d4d');//黑色
                 }
                //console.log( this.text_color);
              }


            }

          },
         methods:{
             cleanData(){
                 this.stus_=[]
             },
            setScore(score){
                this.stus_[this.workData.index].score=score

            },
            sendMsgToParent(){
                this.$emit("listenToChildEvent","this  from thasdadae chid commponent")
            },
            lisnTeacher(data){
              if(data==0){
                this.stus_=this.stus_data;
                //颜色处理
                this.text_color=[]
                for(var i=0; i<this.stus_.length;i++){
                    if(this.stus_[i].workStatus=="0"){
                        this.text_color.push('#e70012');//红色
                    }else if(this.stus_[i].workStatus=="-1"){
                        this.text_color.push('#dd8b02');//黄色
                    }else if(this.stus_[i].workStatus=="2"){
                        this.text_color.push('#018e3c');//绿色
                    }else{
                        this.text_color.push('#4d4d4d');//黑色
                    }
                }
              }else if(data==1){
                this.stus_=[];
                this.text_color=[]
                for(var i=0;i<this.stus_data.length;i++){
                  if(this.stus_data[i].workStatus=="0"){
                    this.stus_.push(this.stus_data[i]);
                  }
                }
                //颜色处理
                for(var i=0; i<this.stus_.length;i++){
                    this.text_color.push('#e70012');//红色
                }
              } else if(data==2){
                this.stus_=[];
                this.text_color=[]
                for(var i=0;i<this.stus_data.length;i++){
                  if(this.stus_data[i].workStatus=="-1"){
                    this.stus_.push(this.stus_data[i]);
                  }
                }
                //颜色处理
                for(var i=0; i<this.stus_.length;i++){
                    this.text_color.push('#dd8b02');//黄色
                }
              }
            },
            ckbAll(){
                console.log(this.$refs.ckb_head.checked);
                var ckbArr=this.$refs.ckb;
                 if( this.$refs.ckb_head.checked){//全选
                   console.log(this.$refs.ckb_head.checked);
                   for(var i=0;i<ckbArr.length;i++){
                       if(ckbArr[i].checked==false){
                           ckbArr[i].click();
                       }
                   }
                }else{//全不选
                    for(var i=0;i<ckbArr.length;i++){
                       if(ckbArr[i].checked==true){
                           ckbArr[i].click();
                       }
                   }
                }
            },
            ckbsome(index){
                var _this=this;
                _this.$store.commit('ckbClick',index);
                console.log(index);
            },
            showMsgFromChild3(data){
                 this.showS=data;
             },
             showScore(index){
                var workData={}
                workData.workName=this.stus_[index].task
                workData.stuName=this.stus_[index].name
                workData.course=this.stus_[index].course
                workData.userID=this.stus_[index].num
                workData.score=this.stus_[index].score
                workData.evaluate=this.stus_[index].evaluate
                workData.isTeam=1
                workData.index=index
                this.workData=workData
                this.showS=1;
                console.log(this.showS)
             },
             down_studentWork(index){
                 console.log(index);
                 console.log(this.stus_);
                var workName=this.stus_[index].task
                var course=this.stus_[index].course
                var userID=this.stus_[index].num
               if(this.text_color[index]=='#018e3c'||this.text_color[index]=='#dd8b02'){
                   window.open('/studentWork/download_stu/'+workName+'/'+course+'/'+userID,'_self')
               }else{
                 this.$message({
                   type: 'warning',
                   message: "该学生没有提交作业",
                 })
               }
             }
        },
    }
</script>
<style>
    .sShow{
        display: none;
    }
    #tindv .btn_control{
        float: left;
        margin-left: 10px;
        font-size: 12px;
    }
    /*.text_color_0{
        color:red;
    }
    .text_color_1{
        color:yellow;
    }
    .text_color_2{
        color:green;
    }*/
</style>
